Fix escaping of '#' in parameter values and handling of unescaped '#' in uri#26
Open
nothingmuch wants to merge 4 commits into
Open
Fix escaping of '#' in parameter values and handling of unescaped '#' in uri#26nothingmuch wants to merge 4 commits into
nothingmuch wants to merge 4 commits into
Conversation
5bd409c to
8a1a580
Compare
Contributor
Contributor
|
We thought we could work around it, but it turns out this change is actually vital to shipping a clean API for a stable Payjoin v2 version. Any way we can get prioritized review on this? Thanks in advance. |
3cd3d9b to
f50ebb5
Compare
'#'' is not in the set qchar indirectly defined in BIP 21, and therefore should be escaped. [BIP 21](https://github.com/bitcoin/bips/blob/master/bip-0021.mediawiki#abnf-grammar): > labelparam = "label=" *qchar > messageparam = "message=" *qchar > otherparam = qchar *qchar [ "=" *qchar ] ... > Here, "qchar" corresponds to valid characters of an RFC 3986 URI query > component, excluding the "=" and "&" characters, which this BIP takes > as separators. [RFC 3986 § 3.4](https://www.rfc-editor.org/rfc/rfc3986#section-3.4): > The query component is indicated by the first question mark ("?") > character and terminated by a number sign ("#") character or by the > end of the URI. [RFC 3986 Appendix A](https://www.rfc-editor.org/rfc/rfc3986#appendix-A): > pchar = unreserved / pct-encoded / sub-delims / ":" / "@" > query = *( pchar / "/" / "?" ) ... > pct-encoded = "%" HEXDIG HEXDIG > unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" ... > sub-delims = "!" / "$" / "&" / "'" / "(" / ")" > / "*" / "+" / "," / ";" / "="
Although behavior for when encountering RFC 3986 fragments in BIP 21 URIs is not specified, according to RFC 3986 it is unambiguously not query data and therefore should be excluded from BIP 21 query parameters.
f50ebb5 to
646de25
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The first two commits add test assertions for existing behavior.
The next commit adds a failing test for parameter values containing '#', which should be escaped. The commit after that addresses this by specifying a more precise character set, causing the test to pass and should therefore be squashed into it before merge to preserve bisectability. For ease of review they were added separately.
The last three commits add two additional failing tests for correct handling of fragment (unescaped #) followed by a fix commit, and should also be squashed. This set of changes might be considered incomplete without a capability to parse RFC 3986 fragments analogous to the
Extrasmechanism, but since this is not specified in BIP 21 arguably this data should be extracted using theurlcrate.